package com.david.gateway.utils;
import lombok.experimental.UtilityClass;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.nio.charset.StandardCharsets;

/**
 */
@UtilityClass
public class GatewayUtil {

    /**
     * 网关抛异常
     *
     */
//    public static Mono<Void> getVoidMono(ServerWebExchange serverWebExchange, RestModel restModel) {
//        serverWebExchange.getResponse().setStatusCode(HttpStatus.OK);
//        serverWebExchange.getResponse().getHeaders().add(CommonConstant.HEADER_CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE);
//        byte[] bytes = new Gson().toJson(restModel).getBytes(StandardCharsets.UTF_8);
//        DataBuffer buffer = serverWebExchange.getResponse().bufferFactory().wrap(bytes);
//        return serverWebExchange.getResponse().writeWith(Flux.just(buffer));
//    }
}
